package com.yogee.topseller.activity.tianyan;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.core.utils.ToastUtils;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.base.HttpActivity;
import com.yogee.topseller.adapter.BzxrAdapter;
import com.yogee.topseller.adapter.QyfxAdapter;
import com.yogee.topseller.bean.BzxrBean;
import com.yogee.topseller.bean.DetailBean;
import com.yogee.topseller.bean.QyfxBean;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.layout.TitleLayout;
import com.yogee.topseller.utils.AppUtil;
import com.yogee.topseller.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class QyfxActivity extends HttpActivity {

    @BindView(R.id.add_card_titlelayout)
    TitleLayout titlelayout;
    @BindView(R.id.rv_zxfx)
    RecyclerView rv_zxfx;
    @BindView(R.id.rv_zbfx)
    RecyclerView rv_zbfx;
    @BindView(R.id.ll_zsfx)
    LinearLayout ll_zsfx;
    @BindView(R.id.ll_zbfx)
    LinearLayout ll_zbfx;
    @BindView(R.id.id_empty_view)
    View id_empty_view;


    QyfxAdapter adapter1,adapter2;

    private String type = "";
    private String companyId="";
    String cmpanyType="";
    private String proId = "";
    @Override
    protected int getLayoutId() {
        return R.layout.activity_detail_qyfx;
    }

    @Override
    protected void initView() {
        titlelayout.setActivity(this);
        titlelayout.setTitle(getIntent().getStringExtra("title"));
        cmpanyType = getIntent().getStringExtra("cmpanyType");
        type =  getIntent().getStringExtra("type");
        companyId = getIntent().getStringExtra("companyId");
        proId = getIntent().getStringExtra("proId");

        rv_zxfx.setLayoutManager(new LinearLayoutManager(this));
        adapter1 = new QyfxAdapter(this);
        rv_zxfx.setAdapter(adapter1);

        rv_zbfx.setLayoutManager(new LinearLayoutManager(this));
        adapter2 = new QyfxAdapter(this);
        rv_zbfx.setAdapter(adapter2);

//        initQyfx((QyfxBean) getIntent().getSerializableExtra("info"));
        initQyfx();
    }


    private void initQyfx(){
//        if(o.getEyeCheck().getResult().getInternal()==0){
//            ll_zsfx.setVisibility(View.GONE);
//        }else{
//            ll_zsfx.setVisibility(View.VISIBLE);
//            adapter1.addData(o.getEyeCheck().getResult().getInternalList());
//        }
//
//        if(o.getEyeCheck().getResult().getExternal()==0){
//            ll_zbfx.setVisibility(View.GONE);
//        }else{
//            ll_zbfx.setVisibility(View.VISIBLE);
//            adapter2.addData(o.getEyeCheck().getResult().getExternalList());
//        }
        HttpManager.getInstance().eyeCheckQyfx(companyId,type, AppUtil.getUserId(QyfxActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<QyfxBean>() {
            @Override
            public void onNext(QyfxBean o) {
                try{
                    if(o.getEyeCheck().getError_code()==0){

                        if(o.getEyeCheck().getResult().getInternal()==0&&o.getEyeCheck().getResult().getExternal()==0){
                            id_empty_view.setVisibility(View.VISIBLE);
                        }else{
                            if(o.getEyeCheck().getResult().getInternal()==0){
                                ll_zsfx.setVisibility(View.GONE);
                            }else{
                                ll_zsfx.setVisibility(View.VISIBLE);
                                adapter1.addData(o.getEyeCheck().getResult().getInternalList());
                            }

                            if(o.getEyeCheck().getResult().getExternal()==0){
                                ll_zbfx.setVisibility(View.GONE);
                            }else{
                                ll_zbfx.setVisibility(View.VISIBLE);
                                adapter2.addData(o.getEyeCheck().getResult().getExternalList());

                            }
                        }



                    }else{
//                        ll_zsfx.setVisibility(View.VISIBLE);
                        id_empty_view.setVisibility(View.VISIBLE);
//                        ToastUtils.showToast(QyfxActivity.this,o.getEyeCheck().getReason());
                    }
                }catch ( Exception e){
                    ll_zsfx.setVisibility(View.VISIBLE);
                    id_empty_view.setVisibility(View.VISIBLE);
                }


            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
//                LogUtils.e("企业风险",e.toString());
            }
        }, this));
    }

    @Override
    public void showMsg(String msg) {
//        super.showMsg(msg);
        ll_zsfx.setVisibility(View.VISIBLE);
    }
}
